package com.sgcc.electricjournal.util;


import org.apache.poi.hssf.usermodel.HSSFCell;

import org.apache.poi.ss.usermodel.Cell;

import java.math.BigDecimal;


public class CommonUtil {

    public static String getStringFromCell(Cell cell){
        String result = null;
        if (cell == null) {
            return result;
        }
        switch (cell.getCellType()) {
            case HSSFCell.CELL_TYPE_BLANK:
                // 空白
                break;
            case HSSFCell.CELL_TYPE_BOOLEAN:
                // 布尔类型
                break;
            case HSSFCell.CELL_TYPE_ERROR:
                // 故障
                break;
            case HSSFCell.CELL_TYPE_FORMULA:
                // 公式
                break;
            case HSSFCell.CELL_TYPE_NUMERIC:
                // 数字
                Double cellinfo = cell.getNumericCellValue();
                if (null != cellinfo) {
                    result = cellinfo.toString();
                }
                break;
            case HSSFCell.CELL_TYPE_STRING:
                result = cell.getStringCellValue();
                // 公式
                break;
            default:
                break;
        }
        if (com.github.pagehelper.StringUtil.isNotEmpty(result)) {
            result = result.trim();
        }
        return result;
    }

    public static BigDecimal getBigdeCimalFromString(String str){
        str = ((String)StringUtil.ifNullToBlank(str)).trim();
        if(com.github.pagehelper.StringUtil.isEmpty(str)){
            return null;
        }
        try{
            return new BigDecimal(str);
        }catch (Exception e){}
        return null;
    }

}
